package com.relytosoft.mizar.media.display.services.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.relytosoft.dubhe.common.core.base.page.PageQuery;
import com.relytosoft.mizar.media.display.api.entity.Ptz;
import com.relytosoft.mizar.media.display.services.mapper.PtzMapper;
import com.relytosoft.mizar.media.display.services.service.PtzService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 云台信息业务实现类
 *
 * @author hj
 * @version 1.0
 * @date 2022/4/6 15:31
 * @ClassName PtzServiceImpl
 */
@Service
public class PtzServiceImpl extends ServiceImpl<PtzMapper, Ptz> implements PtzService {

    @Override
    public IPage<Ptz> selectPtzPageList(PageQuery pageQuery, Ptz ptz) {
        LambdaQueryWrapper<Ptz> wrapper = Wrappers.lambdaQuery();
        if(StrUtil.isBlank(pageQuery.getOrderByColumn())) {
            pageQuery.setOrderByColumn("CREATED_TIME");
            pageQuery.setIsAsc("desc");
        }
        return this.page(pageQuery.build(), wrapper);
    }



    @Override
    public List<Ptz> selectPtzList(Ptz ptz) {
        LambdaQueryWrapper<Ptz> wrapper = Wrappers.lambdaQuery();
        Integer channelId = ptz.getChannelId();
        Integer id = ptz.getId();
        wrapper.eq(Objects.nonNull(id),Ptz::getId,id)
                .eq(Objects.nonNull(channelId),Ptz::getChannelId,channelId);
        return list(wrapper);
    }




}
